Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination support and also support ?whereIn= in the query string #15

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

nabilfreeman
Copy link

@nabilfreeman nabilfreeman commented Jul 17, 2019

Hey there, we got pagination working in a nice way. We mentioned we were working on it here: #14

In your query string, you can specify ?page=1&page_size=250. The response will then be paginated to the first 250 results.

We have hardcoded id to be descending, so it's always newest to oldest. Let us know if this is ok, there is currently no user ordering option in Kalamata.

If you leave page blank, nothing will happen. It's required.
If you leave page_size blank, it will default to 100. Supplying page_size without page will also do nothing
If you set page_size to 99999 or something greater than the total pages, it will just return the full list on one page.

We took a leaf out of Wordpress wp-json's book for defining the next pages.

In this example, we'll query our API with /users?where={"type":"CUSTOMER"}&page=2&page_size=250.

In the response headers, you will get the following:

Header Value
x-next /users?where={"type":"CUSTOMER"}&page=3&page_size=250
x-prev /users?where={"type":"CUSTOMER"}&page=1&page_size=250
x-total-pages 43
x-total-items 10610

When you reach the first or last page, x-prev or x-next will be accordingly undefined. This is how you know you've reached the boundaries of the page list.

Would appreciate any feedback. We also bumped the version to 0.2 as although everything should continue working as normal for existing people not using ?page= there were some architecture changes and a new node module for query string manipulation.

nabilfreeman and others added 22 commits April 27, 2017 16:51
Add pagination in app.get for Collections
…s is bad practice because load and where are both optional so we should only put them in the URL if they are actually supplied.
…s cleaner because it's clear that where is one of many optional parameters.
@nabilfreeman nabilfreeman changed the title Pagination support Pagination support and also support ?whereIn= in the query string Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants